home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Audio / AC3 / AC3Dec / bitstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-06  |  1.9 KB  |  77 lines

  1. /* 
  2.  *  bitstream.h
  3.  *
  4.  *    Copyright (C) Aaron Holtzman - Dec 1999
  5.  *
  6.  *  This file is part of ac3dec, a free AC-3 audio decoder
  7.  *    
  8.  *  ac3dec is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  ac3dec is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24. //My new and improved vego-matic endian swapping routine
  25. //(stolen from the kernel)
  26. #ifdef WORDS_BIGENDIAN
  27.  
  28. #    define swab32(x) (x)
  29.  
  30. #else
  31.  
  32. #    if defined (__i386__)
  33.  
  34. #    define swab32(x) __i386_swab32(x)
  35.     static inline const uint_32 __i386_swab32(uint_32 x)
  36.     {
  37.         __asm__("bswap %0" : "=r" (x) : "0" (x));
  38.         return x;
  39.     }
  40.  
  41. #    else
  42.  
  43. #    define swab32(x)\
  44. ((((uint_8*)&x)[0] << 24) | (((uint_8*)&x)[1] << 16) |  \
  45.  (((uint_8*)&x)[2] << 8)  | (((uint_8*)&x)[3]))
  46.  
  47. #    endif
  48. #endif
  49.  
  50. extern uint_32 bits_left;
  51. extern uint_32 current_word;
  52.  
  53. void bitstream_init(void(*fill_function)(uint_8**,uint_8**));
  54.  
  55. uint_8 bitstream_get_byte(void);
  56.  
  57. uint_8 *bitstream_get_buffer_start(void);
  58. void bitstream_buffer_frame(uint_32 frame_size);
  59.  
  60. uint_32 bitstream_get_bh(uint_32 num_bits);
  61.  
  62. static inline uint_32 
  63. bitstream_get(uint_32 num_bits)
  64. {
  65.     uint_32 result;
  66.     
  67.     if(num_bits < bits_left)
  68.     {
  69.         result = (current_word << (32 - bits_left)) >> (32 - num_bits);
  70.         bits_left -= num_bits;
  71.         return result;
  72.     }
  73.  
  74.     return bitstream_get_bh(num_bits);
  75. }
  76.  
  77.